/*******************************************************************************
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 ******************************************************************************/
package org.fancyears.helper;

import java.awt.Window;

/**
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月3日 下午3:05:15
 * @Description:
 */
public class LocationHeklper {
	/**
	 * 设置窗口居中
	 * 
	 * @param window 窗口类型，目前常用的是JFrame和JDialog，只要是继承Window的类型都可以设置居中显示
	 * @throws Exception
	 */
	public static void setToCenter(Window window) throws Exception {
		if (null == window) {
			throw new Exception("Window 不能为null");
		}
		int h = window.getHeight();
		int w = window.getHeight();
		if (0 != h && 0 != w) {
			window.setLocationRelativeTo(window.getOwner());
		} else {
			throw new Exception("Window 没有设置大小");
		}
	}

}
